// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3,4,5 - The three creations it can summon. GIVE THE IN-GAME NUMBER
//   Cell 6 - Talking node

begincreaturescript;

variables;

short i,target;
short last_spawn;
short r1;
short last_abil;
short used_abil;
short num_shaped = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Litalia");
	set_level(ME,35);
	change_max_health(ME,300);
	set_boss_level(ME,2);
	
	last_spawn = get_current_tick();
	last_abil = get_current_tick();
	
	set_resistance(ME,7,90);
	
	if (gf(34,9) == 11)
		erase_char(ME);
	if (gf(100,16) > 0)
		erase_char(ME);

	break;

beginstate DEAD_STATE;
	sf(101,9,1);
	sf(100,6,3);
	begin_talk_mode(10);
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
			set_state(3);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if ((get_attitude(ME) >= 10) && (dist_to_pc() <= 40)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}
		
	if (my_dist_from_start() >= 6) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}


	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((tick_difference(last_spawn,get_current_tick()) > 1) && (get_attitude(ME) >= 10) && 
	  (get_nearest_party_char(8) >= 0) && 
	  ((get_ran(1,0,100) < 75) || (friends_nearby(4) == 0)) && (num_shaped < 8)) {
		r1 = get_ran(1,0,2);
		if ((get_memory_cell(3 + r1) > 0) && (char_ok(get_memory_cell(3 + r1)) == FALSE)) {
			if (summon_creature(get_memory_cell(3 + r1) - 8)) {
				num_shaped = num_shaped + 1;
				print_named_str(ME,"makes a new creation!");
				set_summon_level(get_memory_cell(3 + r1),1);
				place_particle_num(get_memory_cell(3 + r1),10,7,10);
				
				run_char_animation(2,1,50);	
				pc_heard_sound_delay(136,100);						
				
				last_spawn = get_current_tick();
				end();
				}
			}
		}

	used_abil = 0;
	if ( (tick_difference(last_abil,get_current_tick()) > 0) && (get_attitude(ME) >= 10) && (is_combat()) && (get_nearest_party_char(8) >= 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();
		used_abil = 1;

		if ((get_char_status(ME,1) <= 0) && (get_ran(1,0,100) < 40)) {
			print_named_str(ME,"calls forth a blessing!");
			pc_heard_sound_delay(101,250);						
		  	place_particle_num(ME,3,0,8);
			status_nearby(8,8,0,1);
			status_nearby(8,8,1,1);
			status_nearby(8,8,8,1);
			status_nearby(8,8,12,1);
			status_nearby(8,8,10,1);
			}
			else {
				place_particle_num(ME,4,6,8);
				print_named_str(ME,"emits an aura of terror.");
				pc_heard_sound_delay(107,250);						
				status_nearby(75,6,7,0);
				}

		}
	if (used_abil)
		end();
		
	do_attack();
break;

beginstate TALKING_STATE;
	begin_talk_mode(170);
break;